using UnityEngine;
using System.Collections;

public class Inst : MonoBehaviour 
{
    int id = 3;
        
	void Start () 
	{
		this.gameObject.AddComponent("MeshRenderer");
        this.gameObject.AddComponent("MeshFilter");
		this.gameObject.AddComponent("BoxCollider");
		this.gameObject.GetComponent<BoxCollider>().size = new Vector3(3, 2, 0);
		this.gameObject.tag = "Jogar";
		
        Mesh mesh = Quad.Create(1, 0.5f);
		
        this.gameObject.GetComponent<MeshFilter>().mesh = mesh;
        this.gameObject.GetComponent<MeshRenderer>().material = AtlasManager.globalMaterial;

        this.gameObject.GetComponent<MeshFilter>().mesh.uv = new Vector2[]
        {
           new Vector2(AtlasManager.rects[id].xMin, AtlasManager.rects[id].yMax),
           new Vector2(AtlasManager.rects[id].xMax, AtlasManager.rects[id].yMax),
           new Vector2(AtlasManager.rects[id].xMax, AtlasManager.rects[id].yMin),
           new Vector2(AtlasManager.rects[id].xMin, AtlasManager.rects[id].yMin)
        };

        this.transform.position = new Vector3(-4.780433f, 4, 0);   
	}
	
	void Update () 
	{
	
	}

    void OnMouseDown()
    {
        if (id == 3)
        {
            id = 4;
            Mesh mesh = Quad.Create(1, 1.4f);
            this.gameObject.GetComponent<BoxCollider>().size = new Vector3(3, 2, 0);
            this.gameObject.GetComponent<MeshFilter>().mesh = mesh;
            this.gameObject.GetComponent<MeshRenderer>().material = AtlasManager.globalMaterial;
            this.gameObject.GetComponent<MeshFilter>().mesh.uv = new Vector2[]
            
            {
               new Vector2(AtlasManager.rects[id].xMin, AtlasManager.rects[id].yMax),
              new Vector2(AtlasManager.rects[id].xMax, AtlasManager.rects[id].yMax),
              new Vector2(AtlasManager.rects[id].xMax, AtlasManager.rects[id].yMin),
              new Vector2(AtlasManager.rects[id].xMin, AtlasManager.rects[id].yMin)
            };


            this.transform.position = new Vector3(-4.780433f, 3.1f, 0);
        }
        else if (id == 4)
        {
            id = 3;
            Mesh mesh = Quad.Create(1, 0.5f);

            this.gameObject.GetComponent<MeshFilter>().mesh = mesh;
            this.gameObject.GetComponent<MeshRenderer>().material = AtlasManager.globalMaterial;
            this.gameObject.GetComponent<MeshFilter>().mesh.uv = new Vector2[]
        {
           new Vector2(AtlasManager.rects[id].xMin, AtlasManager.rects[id].yMax),
           new Vector2(AtlasManager.rects[id].xMax, AtlasManager.rects[id].yMax),
           new Vector2(AtlasManager.rects[id].xMax, AtlasManager.rects[id].yMin),
           new Vector2(AtlasManager.rects[id].xMin, AtlasManager.rects[id].yMin)
        };

            this.transform.position = new Vector3(-4.959309f, 4, 0);   
        }
    }
}
